package com.hxzy.ui;

import com.hxzy.bean.Film;
import com.hxzy.service.FilmService;
import com.hxzy.service.Impl.FilmServiceImpl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class Test {
    private static Scanner input= new Scanner(System.in);
    private static FilmService service= new FilmServiceImpl();
    public static void main(String[] args) {
        //add();
        findByID();
        //queryAll();
    }

    /**
     * 向Film表中添加数据
     */
    private static void add(){
        System.out.println("请输入中文名称");
        String name =input.next();
        System.out.println("请输入英文名称");
        String name1 =input.next();
        System.out.println("请输入电影类型");
        String type =input.next();
        System.out.println("请输入上映地区");
        String space=input.next();
        System.out.println("请输入持续的时间");
        double time= input.nextDouble();
        System.out.println("请输入上映的时间格式如:2020-09-10/08-12-55");
        String str=input.next();
        String year_str = str.substring(0, 4);
        int year = Integer.parseInt(year_str);
        System.out.println(year);
        String month_str = str.substring(5, 7);
        int month_num = Integer.parseInt(month_str);
        Month month = Month.of(month_num);
        System.out.println(month);
        String date_str = str.substring(8, 10);
        int day = Integer.parseInt(date_str);
        String hour_str = str.substring(11, 13);
        int hour = Integer.parseInt(hour_str);
        String minute_str = str.substring(14, 16);
        int minute = Integer.parseInt(minute_str);
        String second_str = str.substring(17, 19);
        int second = Integer.parseInt(second_str);
        LocalDateTime time1 = LocalDateTime.of(year, month, day, hour, minute, second);
        //System.out.println(time);
        Film film= new Film(55,name,name1,type,space,time,time1);
        int num = service.save(film);
        System.out.println(num>0?"添加成功":"添加失败");
    }

    /**
     * 根据电影的ID 修改信息
     */
    private static void update(){
        System.out.println("请输入要修改ID");
        int id = input.nextInt();
        System.out.println("请输入中文名称");
        String name =input.next();
        System.out.println("请输入英文名称");
        String name1 =input.next();
        System.out.println("请输入电影类型");
        String type =input.next();
        System.out.println("请输入上映地区");
        String space=input.next();
        System.out.println("请输入持续的时间");
        double time= input.nextDouble();
        System.out.println("请输入上映的时间格式如:2020-09-10/08-12-55");
        String str=input.next();
        String year_str = str.substring(0, 4);
        int year = Integer.parseInt(year_str);
        System.out.println(year);
        String month_str = str.substring(5, 7);
        int month_num = Integer.parseInt(month_str);
        Month month = Month.of(month_num);
        System.out.println(month);
        String date_str = str.substring(8, 10);
        int day = Integer.parseInt(date_str);
        String hour_str = str.substring(11, 13);
        int hour = Integer.parseInt(hour_str);
        String minute_str = str.substring(14, 16);
        int minute = Integer.parseInt(minute_str);
        String second_str = str.substring(17, 19);
        int second = Integer.parseInt(second_str);
        LocalDateTime time1 = LocalDateTime.of(year, month, day, hour, minute, second);
        Film film= new Film(id,name,name1,type,space,time,time1);
        int num = service.save(film);
        System.out.println(num>0?"修改成功":"修改失败");
    }

    /**
     * 根据id删除数据
     */
    private static void remove(){
        System.out.println("请输入要删除的ID");
        int id=input.nextInt();
        int num = service.remove(id);
        System.out.println(num>0?"删除成功":"删除失败");
    }

    /**
     * 全查表中的信息
     */
    private static void queryAll(){
        List<Film> films = service.queryAll();
        films.stream().forEach(System.out::println);
    }

    /**
     * 根据ID查询信息
     */
    private static void findByID(){
        System.out.println("请输入要查询的ID");
        int id =input.nextInt();
        Film film = service.findByID(id);
        System.out.println(film);
    }


}
